<?php

if ($_SERVER['SERVER_PORT']!=443) {
	$sslport=443; //whatever your ssl port is
	$url = "https://". $_SERVER['SERVER_NAME'] . ":" . $sslport . $_SERVER['REQUEST_URI'];
	header("Location: $url");
}
$ini = ini_set("soap.wsdl_cache_enabled", 0);
if(isset($_SESSION['cart']['customer_id'])){
	$sslport=443; //whatever your ssl port is
	$url = "https://". $_SERVER['SERVER_NAME'] . ":" . $sslport . '/index.php'.$_SERVER['REQUEST_URI'].'&page=cart-login';
	header("Location: $url");
	exit();
}

if(!isset($_COOKIE['MySession'])){
	$url = "https://".$_SERVER['SERVER_NAME']."/freeway/custom/webservices/index.php?service=Session";
	$Client = new SoapClient($url);
	$this_Session = $Client->returnSID();
	setcookie('MySession', $this_Session);
	unset($Client);	
}
else 
	$this_Session = $_COOKIE['MySession'];


	
//print_r($_SESSION);
	
if((isset($_GET[item]) && $_GET[item] !=null) && (isset($_GET[session]) && $_GET[session] != null)){
	$item = $_GET[item];
	$item_session = $_GET[session];

	$url = "https://".$_SERVER['SERVER_NAME']."/freeway/custom/webservices/index.php?service=ShoppingCart";
	$Client = new SoapClient($url);
	$Client->__setCookie('ws_freeway', $this_Session);
	if(isset($_SESSION[cart][customer_id])){
		$Client->__setCookie('customer_id', $_SESSION[cart][customer_id]);
	}
	$products_id = $item;
	$customers_basket_quantity = 1;
	$products_type = 'E';
	$old_orders_id = 0;
	$answer_type = null;
	$answer_value = null;
	$session_id = $item_session;
	
	$debug = $Client->GuestBasketAdd($products_id, $customers_basket_quantity, $products_type, $old_orders_id, $answer_type, $answer_value, $session_id);
}
/*
//Uncomment to view errors
echo '<pre>';
print_r($debug);
echo '</pre>'; 
*/
unset($Client);
unset($debug);

$registration_url = '/index.php?page=registration';
$login_action_url ='/index.php?page=cart-login';
$register = '<a href='. $registration_url . '>Register</a>';
	$login_form  = '<form id="login" method="post" action="'.$login_action_url.'" enctype="multipart/form-data" style="margin: 8px; text-align: left; float: left;">';
	$login_form .= '<div class="formbuilder" style="margin: 8px; text-align: left; float: left;"><div class="required text2-0">';
	$login_form .= '		<label for="email">E-mail: <span class="required_symbol">*</span></label>';
	$login_form .= '		<input type="text" name="email" id="email" value="" size="25" maxlength="128" />';
	$login_form .= '	</div>';
	$login_form .= '	<div class="required text2-0">';
	$login_form .= '		<label for="password">Password: <span class="required_symbol">*</span></label>';
	$login_form .= '		<input type="password" name="password" id="password" value="" size="25" maxlength="128" />';
	$login_form .= '	</div>';
	$login_form .= '	<div class="submit">';
	$login_form .= '	<script type="text/javascript">';
	$login_form .= '	/* <!-- <![CDATA[ */';
	$login_form .= '    var submitted = 0;';
	$login_form .= '    function LockButton ()';
	$login_form .= '       {';
	$login_form .= '       var ret = false;';
	$login_form .= '       if ( ! submitted )';
	$login_form .= '          {';
	$login_form .= '           var item = document.getElementById("fbsubmit");';
	$login_form .= '           if (item != null)';
	$login_form .= '             {';
	$login_form .= '             setTimeout(function() {item.disabled = true}, 0);';
	$login_form .= '             }';
	$login_form .= '           submitted = 1;';
	$login_form .= '           ret = true;';
	$login_form .= '          }';
	$login_form .= '        return ret;';
	$login_form .= '        }';
	$login_form .= '    /* ]]> --> */';    
	$login_form .= '	</script><input name="submit" value="Login" type="submit" class="fbsubmit" id="fbsubmit" onclick="return LockButton()" />';
	$login_form .= '</div>';
	$login_form .= '</div>';
	$login_form .= '</form>';



echo "<h3>Please $register or login</h3> $login_form";

?>